#ifndef _GUI_PROGRAMWND_H
#define _GUI_PROGRAMWND_H

#include <QWidget>
#include "ui_programwnd.h"

class ProgramTableDelegate;
class SysController;

class ProgramWnd : public QWidget {
	Q_OBJECT

public:
	ProgramWnd(QWidget *parent = 0);
	~ProgramWnd();

private slots:
	void wndShouldReturn();

	void onCellClicked(int r, int c);
	void onNewClicked();
	void onSaveClicked();
	void onInsertClicked();
	void onDeleteClicked();

	void deviceTypeChanged(const QString& type);
	void SwitchFrame();
	void refreshItem(int item_index);

private:
//	enum ItemRows {
//		kItemRowNameSuffixCh = 0,
//		kItemRowBias,
//		kItemRowWaitTime,
//		kItemRowMeas,
//		kItemRowFilter,
//		kItemRowVolLimit,
//		kItemRowLimitJudge,
//		kItemRowCount
//	};
	enum ItemRow {
		kItemRowNameSuffixCh = 0,
		kItemRowBiasRng,
		kItemRowBiasVal,
		kItemRowWaitTime,
		kItemRowMeasRng,
		kItemRowMeasValLower,
		kItemRowMeasValUpper,
		kItemRowFilter,
		kItemRowVolLimit,
		kItemRowLimitJudge,
		kItemRowCount
	};

	void Init();
	void LoadItem(int item_index);
	void LoadItemsFrom(int from_index);
	int InsertItem(int item_index);
	int DeleteItem(int item_index);

	// whether the column's table widget item is not created
	bool IsColumnEmpty(int col) const;
	// create table widgets
	void CreateColumnWidgets(int col);

	Ui_ProgramWnd ui;
	ProgramTableDelegate *delegate_;
	SysController *sys_;
};

#endif // _GUI_PROGRAMWND_H
